import React, { Component } from 'react';
import _ from 'lodash';
import Former, { validate } from '../../../components/Former';
import Button from '../../../components/Button';
import { jobType, educationType } from '../../../common/baseData';
import detail from '../models/customer';

export default class From extends Component {
  _validate = () => {
    validate((err, val) => {
      if (!err && _.isFunction(this.props.onSubmit)) {
        if (detail.customer.customerId) {
          val.customerId = detail.customer.customerId;
          this.props.onSubmit(val);
        }
      }
    });
  };
  render() {
    const { customer = {} } = detail;
    const fields = [
      {
        label: '学历',
        placeholder: '请选择客户学历',
        type: 'Selecter',
        key: 'educationType',
        initialValue: customer.educationType,
        options: educationType
      },
      {
        label: '职业',
        placeholder: '请选择客户职业',
        type: 'Selecter',
        key: 'jobType',
        initialValue: customer.jobType,
        options: jobType
      },
      {
        label: '亲密度',
        placeholder: '请输入客户亲密度',
        type: 'Number',
        key: 'intimateDegree',
        step: 10,
        maximumValue: 500,
        minimumValue: 0,
        allowEdit: true,
        initialValue: customer.intimateDegree || 0,
      },
      {
        label: '年收入(万元)',
        placeholder: '请选择客户性别',
        type: 'Number',
        key: 'annualSalary',
        step: 10,
        maximumValue: 500,
        minimumValue: 0,
        allowEdit: true,
        initialValue: customer.annualSalary || 0,
      },
    ];
    return (
      <Former
        fields={fields}
        bottom={
          <Button
            onPress={this._validate}
            type="primary"
            title="更新客户资料"
          />
        }
      />
    );
  }
}
